package com.zhz.common.tool.oss.autoconfig;

import com.zhz.common.tool.oss.aliyun.AliyunOssProperties;
import com.zhz.common.tool.oss.aliyun.AliyunOssServiceImpl;
import com.zhz.common.tool.oss.aws.AwsOssProperties;
import com.zhz.common.tool.oss.aws.AwsOssServiceImpl;
import com.zhz.common.tool.oss.huaweicloud.HuaweiCloudOssProperties;
import com.zhz.common.tool.oss.huaweicloud.HuaweiCloudOssServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * oss自动装配
 *
 * @author zhouhengzhe
 */
@Slf4j
@Configuration
@EnableConfigurationProperties({AliyunOssProperties.class, HuaweiCloudOssProperties.class, AwsOssProperties.class})
public class OssAutoConfiguration {

    @Bean(name = "aliyunOssService")
    @ConditionalOnProperty(prefix = "ihrm.oss.aliyun", name = "enable", havingValue = "true")
    public AliyunOssServiceImpl aliyunOssService(AliyunOssProperties aliyunOssProperties) {
        return new AliyunOssServiceImpl(aliyunOssProperties);
    }

    @Bean(name = "huaweiCloudOssService")
    @ConditionalOnProperty(prefix = "ihrm.oss.huaweicloud", name = "enable", havingValue = "true")
    public HuaweiCloudOssServiceImpl huaweiCloudOssService(HuaweiCloudOssProperties huaweicloudOssProperties) {
        return new HuaweiCloudOssServiceImpl(huaweicloudOssProperties);
    }

    @Bean(name = "awsOssService")
    @ConditionalOnProperty(prefix = "ihrm.oss.aws", name = "enable", havingValue = "true")
    public AwsOssServiceImpl awsOssService(AwsOssProperties awsOssProperties) {
        return new AwsOssServiceImpl(awsOssProperties);
    }

}
